/* 
 * File:   DisplayMonitor.cpp
 * Author: Martijn
 * 
 * Created on 22 juni 2010, 16:43
 */

#include "DisplayMonitor.h"
#include "pRTOS.h"
#include "LCDDisplay.h"

void DisplayMonitor::enable() {
    theLCD.enable();
    suspend();
}

void DisplayMonitor::disable(void) {
    theLCD.disable();
    suspend();
}

void DisplayMonitor::init(void) {
    suspend();
}

void DisplayMonitor::update(void) {
  int index;
    switch (state) {
        case ENABLED:
            state = WAITING;
            dmtChan.read();
            break;

        case WAITING:
            di = dmtChan.getItem();
            index = 0;
            theLCD.gotoRowCol(di.row, 0);
            state = FLUSHING;

        case FLUSHING:
            if (index < di.len)
                theLCD.displayChar(di.buf[index++]);
            else {
                state = WAITING;
                dmtChan.read();
            }
            break;
    }
}
